package cn.wsgfz.test;

import java.util.List;

import cn.wsgfz.test.DifficultEntity.DifficultItem;
import cn.wsgfz.testsvgapp.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ListView;
import android.widget.TextView;

public class DifficultDataAdapter extends AbsAdapter<DifficultEntity>{
	public DifficultDataAdapter(Context c, List<DifficultEntity> resource, int col) {
		super(c, resource, col);
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		if(view == null) {
			Holder holder = new Holder();
			LayoutInflater inflater = LayoutInflater.from(getContext());

			view = inflater.inflate(R.layout.data_item_layout, null);
			holder.titleText = (TextView) view.findViewById(R.id.item_title);
			holder.listView  = (ListView) view.findViewById(R.id.data_progress_list);
			
			view.setTag(holder);
		}
		
		Holder holder = (Holder)view.getTag();
		setView(holder, getResource().get(position));
		
		return view;
	}
	
	private void setView(Holder holder, DifficultEntity difficultEntity) {
		holder.titleText.setText(difficultEntity.title);
		List<DifficultItem> lists = difficultEntity.items;
		DifficultItemAdapter adapter = new DifficultItemAdapter(getContext(), lists, 1);
		LayoutParams lp = holder.listView.getLayoutParams();
		lp.height = (lists.size() * holder.listView.getDividerHeight()) + (lists.size() * 50);
		holder.listView.setLayoutParams(lp);
		holder.listView.setAdapter(adapter);
	}

	class Holder {
		TextView titleText;
		ListView listView;
	}
}
